package deng.jbservice.examples.ejb3;

import java.util.Enumeration;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.log4j.Logger;
import org.jboss.ejb3.annotation.Depends;

/**
 * @author Zemian Deng
 * 
 */
@MessageDriven(messageListenerInterface = MessageListener.class, activationConfig = {
		@ActivationConfigProperty(propertyName = "destination", propertyValue = "/queue/ExampleQueue"),
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") })
@Depends("jboss.messaging.destination:service=Queue,name=ExampleQueue")		
public class MsgBean implements MessageListener {

	private static Logger logger = Logger.getLogger(MsgBean.class);

	@Override
	public void onMessage(Message message) {
		logger.info("Received message: " + message);
		try {
			Enumeration<?> names = message.getPropertyNames();
			while( names.hasMoreElements() ) {
				String name = (String)names.nextElement();
				logger.debug("Msg property " + name + " : " + message.getObjectProperty(name));
			}
		} catch (JMSException e) {
			throw new RuntimeException(e);
		}
	}

}
